package cn.stylefeng.guns.modular.wxuser.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.order.model.params.TbOrderParam;
import cn.stylefeng.guns.modular.wxuser.entity.TaoWxUser;
import cn.stylefeng.guns.modular.wxuser.mapper.TaoWxUserMapper;
import cn.stylefeng.guns.modular.wxuser.model.params.TaoWxUserParam;
import cn.stylefeng.guns.modular.wxuser.model.result.TaoWxUserResult;
import  cn.stylefeng.guns.modular.wxuser.service.TaoWxUserService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lcw
 * @since 2019-10-22
 */
@Service
public class TaoWxUserServiceImpl extends ServiceImpl<TaoWxUserMapper, TaoWxUser> implements TaoWxUserService {
    @Autowired
    private TaoWxUserMapper taoWxUserMapper;

    @Override
    public void add(TaoWxUserParam param){
        TaoWxUser entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(TaoWxUserParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(TaoWxUserParam param){
        TaoWxUser oldEntity = getOldEntity(param);
        TaoWxUser newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public TaoWxUserResult findBySpec(TaoWxUserParam param){
        return null;
    }

    @Override
    public List<TaoWxUserResult> findListBySpec(TaoWxUserParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(TaoWxUserParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public void updateNotify(String notify, String openId) {
        taoWxUserMapper.updateNotify(notify,openId);
    }

    @Override
    public int number(String notify, String openId) {
        return taoWxUserMapper.number(notify,openId);
    }

    @Override
    public int num(String openId) {
        return taoWxUserMapper.num(openId);
    }



    /**
     * 修改种草状态
     */
    @Override
    public int updateIsTree(TbOrderParam tbOrderParam) {
        return taoWxUserMapper.updateIsTree(tbOrderParam);
    }



    private Serializable getKey(TaoWxUserParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private TaoWxUser getOldEntity(TaoWxUserParam param) {
        return this.getById(getKey(param));
    }

    private TaoWxUser getEntity(TaoWxUserParam param) {
        TaoWxUser entity = new TaoWxUser();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
